<template>
    <list-item v-if="dataList.length > 0" :dataList="dataList"></list-item>
</template>


<script setup>
    import ListItem from '@/components/ListPage/ListItem.vue'
    import { getListData,getMemuTabs } from '@/api'
    import { onBeforeMount,} from 'vue'
    import { useStore} from '@/store/index.js'
    import { dateFormat } from '@/util/util.js'
    import { storeToRefs } from 'pinia'
    const emits = defineEmits(['refreshContent']);
    
    const store = useStore();

    const { dataList } = storeToRefs(store)

    onBeforeMount(async()=>{
        if(store.curTitle == ''){
            const Tabs  = await getMemuTabs();
            store.updataCurTitle(Tabs.data.list[0])
        }
        let ListData = await getListData(store.curTitle);
        let data;
        if(ListData.data.data.length > 0){
            data = ListData.data.data.map((item)=>{
                return {
                    ...item,
                    updateTime : dateFormat(item.updateTime) 
                }
            })
            store.setLastId(data.slice(-1)[0])
            store.setDataList(data)
            emits('refreshContent')
        }
    })

</script>
  